package com.tron.dobest.java.tronthread;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 提高响应速度
 * 降低资源消耗
 * 便于管理线程
 */
public class Start {
    public static void main(String[] args) {
        //创建线程池
        ThreadPoolExecutor executors = (ThreadPoolExecutor) Executors.newFixedThreadPool(10);
        //强转实现类后可以设置属性
        executors.setCorePoolSize(10);

        executors.submit(()->{
            System.out.println("======线程池创建线程======");
        });
        //关闭线程池
        executors.shutdown();


        //执行器获取线程工厂创建线程并执行
        Executors.defaultThreadFactory().newThread(() -> {
            System.out.println("======默认工厂启动一个线程======");
        }).start();
    }
}
